package cn.com.surker.workcon.common;

import cn.com.surker.handler.BCSCoordinator;
import cn.com.surker.handler.BCSStarter;
import cn.com.surker.task.ProBcsTask;
import cn.com.surker.redis.RedisUtils;
import cn.com.surker.spring.RestResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.Random;

/**
 * @author luotao
 * @date 2024/11/8
 */
@Controller
@RequestMapping("/bcs/test")
public class TestController {

	@Autowired
	private ProBcsTask proSchedul;

	@Autowired
	private BCSStarter bcsStarter;

	@Autowired
	private BCSCoordinator bcsCoordinator;
	@Resource
	private RedisUtils redisUtils;

	/**
	 * 发货单
	 *
	 * @param erpId
	 * @return
	 * @throws IllegalAccessException
	 */
	@RequestMapping(value = "/sync", method = RequestMethod.GET)
	@ResponseBody
	public RestResultDto success(Long erpId) throws IllegalAccessException {
		//proSchedul.syncInvDb();
		//redisUtils.rightPush("luotao-10080", String.valueOf(2));
		//bcsCoordinator.tempSyncMaterial();
		return RestResultDto.success();
	}

	@RequestMapping(value = "/sync2", method = RequestMethod.GET)
	@ResponseBody
	public RestResultDto success2(Long erpId) throws IllegalAccessException {
		//proSchedul.syncInvoice();
		// redisUtils.rightPush("luotao-10080", String.valueOf(3));
		// bcsCoordinator.convertMaterial(72l,null);
		return RestResultDto.success();
	}


	public static void setRandomValues(Object obj) throws IllegalAccessException {
		Random random = new Random();
		Class<?> clazz = obj.getClass();
		for (Field field : clazz.getDeclaredFields()) {
			// 跳过 id 属性
			if ("id".equals(field.getName())) {
				continue;
			}
			field.setAccessible(true);
			// 根据属性类型设置随机值
			if (field.getType() == int.class || field.getType() == Integer.class) {
				field.set(obj, random.nextInt(100));  // 设置 0 到 99 的随机整数
			} else if (field.getType() == double.class || field.getType() == Double.class) {
				field.set(obj, random.nextDouble() * 100);  // 设置 0 到 100 的随机 double 值
			} else if (field.getType() == String.class) {
				field.set(obj, "Random" + random.nextInt(1000));  // 设置一个随机字符串
			} else if (field.getType() == Date.class) {
				field.set(obj, new Date());
			} else if (field.getType() == Long.class) {
				field.set(obj, 10001l);
			}
			// 可扩展其他类型...
		}
	}
}
